import dayjs from 'dayjs'

export default {
	data(){
		return {
			nowTime:new Date(),
			darwTimer:null
		}
	},
	computed:{
		drawBase(){
			const {goods_type,batch}=this.product
			return goods_type==1? this.product:batch
		},
		darwIsOpen(){		
			if(!this.drawBase) return 0
			if(this.drawBase.open_draw){
				this.setNowTimeTimer()
			}
			return this.drawBase.open_draw
		},
		signUpStatus(){  //1未开始，2已开始，3已结束
			if(!this.drawBase) return 1
			let startTime=dayjs(this.drawBase.sign_up_start_time)
			let endTime=dayjs(this.drawBase.sign_up_end_time)
			if(this.nowTime<startTime){
				return 1
			}else if(startTime<=this.nowTime&&this.nowTime<endTime){
				return 2
			}
			return 3
		},
		isDrawed(){
			return this.nowTime>dayjs(this.drawBase.draw_time)
		},
		countDown(){
			let startTime=dayjs(this.drawBase.sign_up_start_time).valueOf()
			let endTime=dayjs(this.drawBase.sign_up_end_time).valueOf()
			switch(this.signUpStatus){
				case 1:
					return startTime-new Date().valueOf()
					break;
				case 2:
					return endTime-new Date().valueOf()
					break;
				case 3:
					return null
					break;
			}
			
		}
	},
	methods:{
		setNowTimeTimer(){
			if(this.darwTimer) clearInterval(this.darwTimer);
			this.darwTimer=setInterval(()=>{
				this.nowTime=new Date()
			},1000)
		}
	}
}